/**
 * 
 */
package com.toncen.samepms.fisher.query;

import javax.servlet.http.HttpServletRequest;

import com.toncen.samepms.common.AbstractMemoryAction;
import com.sky.fisher.db.AbstractConnectionProvider;
import com.sky.fisher.query.AbstractQuery;

/**
 * @author tch
 * 
 */
public class MemoryConnectionProvider extends AbstractConnectionProvider {
	/**
	 * 
	 */
	private HttpServletRequest request;

	/**
	 * 
	 */
	private final static String ACTION_NAME = "actionName";

	/**
	 * 
	 */
	private final static String ATRIBUTE_NAME = "attributeName";

	/**
	 * 
	 */
	private final static String MANY_PROPERTY_NAME = "manyPropertyName";

	/**
	 * 
	 */
	private final static String ONE_PROPERTY_NAME = "onePropertyName";

	/**
	 * 
	 */
	public MemoryConnectionProvider(HttpServletRequest request) {
		super();
		this.request = request;
	}

	@Override
	public void closeConnection(Object con) throws Exception {

	}

	@Override
	public Object getConnection() throws Exception {
		String actionName = request.getParameter(ACTION_NAME);
		String attributeName = request.getParameter(ATRIBUTE_NAME);
		String manyPropertyName = request.getParameter(MANY_PROPERTY_NAME);
		String onePropertyName = request.getParameter(ONE_PROPERTY_NAME);
		return AbstractMemoryAction.getDataMany(request, actionName, attributeName, manyPropertyName, onePropertyName);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sky.fisher.db.AbstractConnectionProvider#getQuery()
	 */
	@Override
	public AbstractQuery getQuery() throws Exception {
		return new MemoryQuery(this);
	}

}
